package com.suyl.candy.model.controller;


import com.suyl.candy.model.entity.BussAccount;
import com.suyl.candy.model.service.BussAccountService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author suyl
 * @since 2020-04-21
 */
@CrossOrigin
@RestController
@RequestMapping("/bussAccount")
public class BussAccountController {

    private Logger log = LoggerFactory.getLogger(BussAccountController.class);
    @Autowired
    BussAccountService bussAccountService;

    @RequestMapping("get")
    @ResponseBody
    public Object get() {
        log.info("1234567890");
        BussAccount bussAccount = new BussAccount();
        bussAccount.setCreateTime(LocalDateTime.now());
        bussAccount.setCatgroy("1");
        bussAccountService.save(bussAccount);
        return bussAccountService.getById(210);
    }

    /**
     * 贷款总额
     * 已对接
     */
    @GetMapping("getTotalLoans")
    @ResponseBody
    public Object getTotalLoans() {
        log.info("getTotalLoans");
        Map<String, BigDecimal> map = new HashMap();
        map.put("totalLoans", bussAccountService.getTotalLoans());
        return map;
    }

    /**
     * 截止今天已还总额
     * 已对接
     *
     * @return
     */
    @GetMapping("getTotalAmountRepaid")
    @ResponseBody
    public Object getTotalAmountRepaid() {
        Map<String, BigDecimal> map = new HashMap();
        map.put("totalAmountRepaid", bussAccountService.getTotalAmountRepaid());
        return map;
    }

    /**
     * 本月贷款总额
     * 已对接
     */
    @GetMapping("getTotalLoansMonth")
    @ResponseBody
    public Object getTotalLoansMonth() {
        Map<String, BigDecimal> map = new HashMap();
        map.put("totalLoansMonth", bussAccountService.getTotalLoansMonth());
        return map;
    }

    /**
     * 截止今天本月已还总额
     * 已对接
     *
     * @return
     */
    @GetMapping("getTotalAmountRepaidMonth")
    @ResponseBody
    public Object getTotalAmountRepaidMonth() {
        Map<String, BigDecimal> map = new HashMap();
        map.put("totalAmountRepaidMonth", bussAccountService.getTotalAmountRepaidMonth());
        return map;
    }

    /**
     * 截止今天各类型已还多少期多少钱
     * 已对接
     *
     * @return
     */
    @GetMapping("getTotalAmountRepaidByType")
    @ResponseBody
    public Object getTotalAmountRepaidByType() {
        return bussAccountService.getTotalAmountRepaidByType();
    }

    /**
     * 截止今天各类型未还多少期多少钱
     * 已对接
     *
     * @return
     */
    @GetMapping("getTotalAmountNotByType")
    @ResponseBody
    public Object getTotalAmountNotByType() {
        return bussAccountService.getTotalAmountNotByType();
    }

    /**
     * 每个月份需要还多少钱
     * 已对接
     *
     * @return
     */
    @GetMapping("getByMonth")
    @ResponseBody
    public Object getByMonth() {
        return bussAccountService.getByMonth();
    }

    /**
     * 截止当前已还，每个月还多少
     *
     * @return
     */
    @GetMapping("getTotalAmountRepaidByMonth")
    @ResponseBody
    public Object getTotalAmountRepaidByMonth() {
        return bussAccountService.getTotalAmountRepaidByMonth();
    }

    /**
     * 截止当前未还，每个月还多少
     *
     * @return
     */
    @GetMapping("getTotalAmountNotByMonth")
    @ResponseBody
    public Object getTotalAmountNotByMonth() {
        return bussAccountService.getTotalAmountNotByMonth();
    }

    /**
     * 最近times次待还款
     * 已对接
     *
     * @return
     */
    @GetMapping("getLatelyNNot")
    @ResponseBody
    public Object getLatelyNNot(int times) {
        return bussAccountService.getLatelyNNot(times);
    }

    /**
     * 最近times次已还款
     * 已对接
     *
     * @return
     */
    @GetMapping("getLately")
    @ResponseBody
    public Object getLately(int times) {
        return bussAccountService.getLately(times);
    }

    /**
     * 本月各类型需还比例
     *
     * @return
     */
    @GetMapping("getCurrentMonthGroupByType")
    @ResponseBody
    public Object getCurrentMonthGroupByType() {
        return bussAccountService.getCurrentMonthGroupByType();
    }
}

